package com.softstao.guoyu.ui.fragment;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.softstao.guoyu.R;
import com.softstao.guoyu.base.BaseFragment;
import com.softstao.guoyu.ui.baseAdapter.RecycleViewBaseAdapter;
import com.softstao.softstaolibrary.library.widget.CustomScrollerView;
import com.softstao.softstaolibrary.library.widget.EmptyLayout;
import com.softstao.softstaolibrary.library.widget.FullyLinearLayoutManager;
import com.wangjie.androidbucket.customviews.borderscrollview.OnScrollChangedListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import in.srain.cube.views.ptr.header.StoreHouseHeader;


public class BaseListFragment<T> extends BaseFragment implements OnScrollChangedListener {
    protected List<T> datas = new ArrayList<T>();
    protected RecycleViewBaseAdapter<T> adapter;
    @BindView(R.id.list) protected RecyclerView mRecycleView;
    @BindView(R.id.head_view)protected LinearLayout headLayout;
    @BindView(R.id.footer_view)protected LinearLayout footerView;
    @BindView(R.id.loading)protected RelativeLayout loading;
    @BindView(R.id.empty_layout)protected EmptyLayout emptyLayout;
    @BindView(R.id.scrollView) protected CustomScrollerView scrollerView;
    @Override
    public int _ContentView() {
        return R.layout.fragment_base_list;
    }
    @Override
    public void initView() {
        StoreHouseHeader header = new StoreHouseHeader(mContext);
        header.setPadding(0, 55, 0, 55);
        header.initWithString(getString(R.string.app_name_en));
        header.setTextColor(getResources().getColor(R.color.colorPrimary));
        header.setScale(1.7f);
        header.onUIReset(ptrFrameLayout);
        setPtrFrameLayoutEnable();
        ptrFrameLayout.setHeaderView(header);
        ptrFrameLayout.addPtrUIHandler(header);
        ptrFrameLayout.setPtrHandler(this);
        mRecycleView.setLayoutManager(new FullyLinearLayoutManager(mContext));
        scrollerView.setOnScrollChangedListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
//        VolleyBuilder.getInstance().setIsList(true);
    }

    @Override
    public void onPause() {
        super.onPause();
//        VolleyBuilder.getInstance().setIsList(false);
    }


    @Override
    public void onRefresh() {
        super.onRefresh();
        loading.setVisibility(View.VISIBLE);
        emptyLayout.setVisibility(View.GONE);
        datas.clear();
    }

    @Override
    public void onLoad() {
        super.onLoad();
        emptyLayout.setVisibility(View.GONE);
    }

    protected void isEmpty(){
        emptyLayout.setVisibility(View.VISIBLE);
    }

    @Override
    public void onScrollChanged(int i, int i1, int i2, int i3) {}

    @Override
    public void onScrollTop() {}

    @Override
    public void onScrollBottom() {
        onLoad();
    }
}
